package com.sage.dao.model;

import java.util.Iterator;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import com.single.commons.StringUtils;

@Entity
@Table(name="i_industry")
//@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
public class Industry extends BeseEntity{
	
	private String name;
	
	@Column(name="pn_key")
	private String pnKey;
	
	private String descript;
	
	@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, targetEntity=Company.class)
	@JoinColumn(name="industry")
	@OrderBy("pn_key")
	private List<Company> companys;
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPnKey() {
		return pnKey;
	}

	public void setPnKey(String pnKey) {
		this.pnKey = pnKey;
	}

	public String getDescript() {
		return descript;
	}

	public void setDescript(String descript) {
		this.descript = descript;
	}

	public List<Company> getCompanys() {
		return companys;
	}

	public void setCompanys(List<Company> companys) {
		this.companys = companys;
	}
	
	
	/**
	 * 查找行业中与给定的companyKey相同的company
	 * @param companyKey
	 * @return
	 */
	public Company getCompany(String companyKey){
		Iterator<Company> iter = getCompanys().iterator();
		while(iter.hasNext()){
			Company company = iter.next();
			if((company.getPnKey().equals(companyKey))){
				return company;
			}
		}
		return null;
	}
	
}
